package cn.iocoder.yudao.module.indicator.controller.admin.index;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.indicator.domain.dto.IndicatorWarnDto;
import cn.iocoder.yudao.module.indicator.domain.entity.IndicatorWarn;
import cn.iocoder.yudao.module.indicator.service.index.IndicatorWarnService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * @author ZYW
 * @description: TODO
 * @date 2024-02-22 16:59
 */
@RestController
@RequestMapping("/indicatorWarn")
public class IndicatorWarnController {
    @Autowired
    IndicatorWarnService indicatorWarnService;

    @PostMapping("/insertIndicatorWarn")
    @Operation(summary = "新增预警指标")
    public CommonResult<Integer> insertIndicatorWarn(@RequestBody IndicatorWarnDto indicatorWarnDto) {
        indicatorWarnService.insertIndicatorWarn(indicatorWarnDto);
        return success(1);
    }

    @GetMapping("/queryWarnRule")
    @Operation(summary = "通过预警指标id查询对应的规则")
    public CommonResult<IndicatorWarnDto> insertIndicatorWarn(String id) {
        IndicatorWarnDto indicatorWarnDto = indicatorWarnService.queryWarnRule(id);
        return success(indicatorWarnDto);
    }

    @PostMapping("/updateWarnRule")
    @Operation(summary = "修改指标")
    public CommonResult<Integer> updateIndicator(@RequestBody IndicatorWarnDto indicatorWarnDto) {
        indicatorWarnService.updateIndicatorWarn(indicatorWarnDto);
        return success(1);
    }
    @GetMapping("/deleteIndicator")
    @Operation(summary = "删除指标")
    public CommonResult<Integer> deleteIndicator(String id) {
        indicatorWarnService.deleteIndicatorWarn(id);
        return success(1);
    }

    @GetMapping("/queryIndicatorWarnList")
    @Operation(summary = "预警指标分页列表")
    public CommonResult<PageResult<IndicatorWarn>> queryIndicatorWarnList(IndicatorWarnDto indicatorWarnDto) {
        PageResult<IndicatorWarn> indicatorWarnPageResult = indicatorWarnService.queryIndicatorsWarnList(indicatorWarnDto);
        return success(BeanUtils.toBean(indicatorWarnPageResult, IndicatorWarn.class));
    }
}
